﻿using System;
using System.Configuration;
using Mammoth.Configurations;
using Mammoth.Repositories;

namespace Mammoth.Services
{
    public class MammothConfig : ConfigurationSection, IDatabaseConfiguration, ICloneable
    {
        const string SectionName = "mammoth";

        public static MammothConfig Load()
        {
            return ConfigurationController.Load<MammothConfig>(MammothConfig.SectionName);
        }

        public void Save()
        {
            this.SaveConfiguration(SectionName);
        }

        [ConfigurationProperty("mockService", DefaultValue = "false")]
        public bool MockService
        {
            get { return (bool)this["mockService"]; }
            set { this["mockService"] = value; }
        }

        [ConfigurationProperty("connectionString", IsRequired = true)]
        public string ConnectionString
        {
            get { return (string)this["connectionString"]; }
            set { this["connectionString"] = value; }
        }


        public object Clone()
        {
            return new MammothConfig()
            {
                ConnectionString = ConnectionString,
                MockService = MockService,
            };
        }
    }
}
